import { JXDef } from "../../../conventions/JXCommon";
import { PRIORITY_VIEW } from "../../../Core/CoreDefine";
import { GCtrl } from "../../../Core/GCtrl";
import GParam from "../../../Core/GEvent/GParam";
import { GListView } from "../../../Core/GView/GListView";
import GViewBase from "../../../Core/GView/GViewBase";
import { AudioMgr } from "../../../Core/Manager/AudioMgr";
import MathEx from "../../../Core/Math/MathEx";
import { BLESS, BLESSEND_INFO, BUFFINFO, CMsg, CURRENCY, DETAILSBTN, EQUIP_PART, ITEM_DETAIL_FLAG, ITEM_TYPE, RedpointEffect, SQUAD_BUTTON } from "../../Common/Define";
import { L } from "../../Common/Language";
import { VIEW_ID } from "../../Common/UI";
import { Res } from "../../Common/UIResources";
import { JXLocales } from "../../Common/Zh";
import { REquireItem } from "../../Data/RunTime/RunRaw/RItemAttach";
import RJXItem from "../../Data/RunTime/RunRaw/RJXItem";
import GameMgr from "../../Logic/GameMgr";
import { IHeroSort } from "../../Logic/HeroMgr";
import JXItem from "../Common/JXItem";
import { JXEBlessAniNames } from "../JXBattle/JXULDefine";

const { ccclass, property, menu, executeInEditMode } = cc._decorator;
@ccclass @menu('View/Home/BlessCtrl')

export default class BlessCtrl extends GViewBase {
    @property({ type: cc.ScrollView, tooltip: "装备视图" }) equipView: cc.ScrollView = null;
    @property({ type: cc.Node, tooltip: "合成视图" }) synthesis: cc.Node = null;
    @property({ type: cc.Node, tooltip: "强化视图" }) strengthen: cc.Node = null;
    @property({ type: cc.Node, tooltip: "可视区域" }) view: cc.Node = null;
    @property({ type: cc.Node, tooltip: "装备存放节点" }) content: cc.Node = null;
    @property({ type: cc.Node, tooltip: "拖拽位置" }) equipArr: Array<cc.Node> = [];
    @property({ type: cc.Node }) equip: cc.Node = null;
    @property({ type: cc.Node }) attribute: cc.Node = null;
    @property({ type: cc.Label, tooltip: '合成金币数量' }) numLab: cc.Label = null;
    @property({ type: cc.Sprite, tooltip: '合成金币图片' }) blessImg: cc.Sprite = null;
    @property({ type: cc.Label, tooltip: "合成等级" }) blessLv: Array<cc.Label> = [];
    @property({ type: cc.Label, tooltip: '强化等级 + 装备名字' }) strLab: cc.Label = null;
    @property({ type: cc.Node, tooltip: "强化信息面板" }) strView: cc.Node = null;
    @property({ type: cc.Label, tooltip: '强化成功率' }) strRate: cc.Label = null;
    @property({ type: cc.Label, tooltip: '观看视频+强化成功率' }) strAdRate: cc.Label = null;
    @property({ type: cc.Label, tooltip: '观看视频+强化成功率' }) strAdRedRate: cc.Label = null;
    @property({ type: cc.Label, tooltip: '强化金币数量' }) strcoinCount: cc.Label = null;

    @property({ type: cc.Node, tooltip: "强化按钮" }) strBtn: cc.Node = null;
    @property({ type: cc.Node, tooltip: "合成按钮" }) synthesisBtn: cc.Node = null;


    @property({ type: sp.Skeleton, tooltip: "强化特效" }) strEffect: sp.Skeleton = null;
    @property({ type: sp.Skeleton, tooltip: "合成特效" }) synthesisEffectL: sp.Skeleton = null;
    @property({ type: sp.Skeleton, tooltip: "合成特效" }) synthesisEffectR: sp.Skeleton = null;


    /**装备视图 */
    private _listView: GListView = null;
    /**英雄热数据 */
    private _IHeroData: IHeroData = null;

    /**是否使用了观看视频增加强化成功率按钮 */
    private _isUseAdRate: boolean = false;
    /**是否累加视频强化成功率 */
    private _isAddAdRate: boolean = false;
    /**正在准备合成或者强化 */
    private _readyBless = [];
    /**合成的2件装备品质 */
    private _trait: number = 1;

    private _qhItem: JXItem = null;
    /**合成视图 */
    protected synthesisView() {
        this.equipArr[BLESS.BLESS0].setScale(1);
        this.equipArr[BLESS.BLESS1].setScale(1);
        this.equipArr[BLESS.BLESS2].setScale(0);
        this.synthesis.active = true;
        this.strengthen.active = false;
        this.equipArr[BLESS.BLESS4].active = true;
        this.delEquip();
    }

    /**强化视图 */
    protected strengthenView() {
        this.synthesis.active = false;
        this.strengthen.active = true;
        this.equipArr[BLESS.BLESS0].setScale(0);
        this.equipArr[BLESS.BLESS1].setScale(0);
        this.equipArr[BLESS.BLESS2].setScale(1);
        this.equipArr[BLESS.BLESS4].active = false;
        this.delEquip();
    }

    protected setRedPoint() {
        let isSync = GameMgr.itemMgr.checkEquipCanSync(this._IHeroData);
        let isLvup = GameMgr.itemMgr.checkHeroEquipCanLvUp(this._IHeroData);
        GameMgr.redMgr.setRPointView(this.equip, this.equip, isLvup, RedpointEffect.REDPOINT);
        GameMgr.redMgr.setRPointView(this.attribute, this.attribute, isSync, RedpointEffect.REDPOINT);
    }

    /**移除视图上的装备 */
    protected delEquip() {
        this._readyBless = [];
        for (let i = 0; i < this.equipArr.length; i++) {
            let child = this.equipArr[i].getChildByName('JXItem');
            if (child) {
                child.destroy();
            }
        }
        this.initEmbattle();
    }

    onGStart(_rHeroData: IHeroData) {
        this.equipArr[BLESS.BLESS2].setScale(0);
        GCtrl.ES.on(CMsg.client.equip.onBlessEquip, this, this.onBlessEquip.bind(this), PRIORITY_VIEW);
        GCtrl.ES.on(CMsg.client.equip.ondelEquip, this, this.initEmbattle.bind(this), PRIORITY_VIEW);

        // GCtrl.ES.on(CMsg.client.equip.onAddEquipSlv, this, this.initEmbattle.bind(this), PRIORITY_VIEW);
        this._IHeroData = _rHeroData;
        let str = GameMgr.lUserData.heroNames(this._IHeroData.tableId);
        GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.blessEquip, { msg: str + "装备" })
        this.node.setContentSize(cc.winSize);
        this.initEmbattle();
        this.setRedPoint();
        this.strengthenView();
    }

    /**关闭界面 */
    public close() {
        this.onClose();
    }

    /**渲染合成强化槽位 */
    protected blessView(info, equipData) {
        let child = this.equipArr[info.site].getChildByName('JXItem');
        if (child) {
            child.destroy();
        }
        this.assetImpl.prefab(Res.prefab.item.jxItem, (prefab: cc.Prefab) => {
            this._readyBless[info.site] = info.equipId;
            let comp = this.assetImpl.addGChild<JXItem>(prefab);
            if (equipData) {
                let equipValue = equipData.itemData;
                let equip = equipValue;
                comp.node.parent = this.equipArr[info.site];
                comp.node.setPosition(0, 0);
                if (info.site == 2) {
                    // console.log(comp.node.position);
                    comp.node.setPosition(0, 110);

                    // 一直重复执行下去

                    cc.tween(comp.node).repeatForever(cc.tween(comp.node)
                        .to(1, { position: cc.v2(0, 150) })
                        .to(1, { position: cc.v2(0, 110) })
                        .start())
                        .start()
                    // console.log(comp.node.position);
                }
                comp.setView(equip, ITEM_DETAIL_FLAG.NO_BG | ITEM_DETAIL_FLAG.BLESS | ITEM_DETAIL_FLAG.SCALEBLESSICON | ITEM_DETAIL_FLAG.FONTHECHENG, () => { }, equipData.insId);
                comp.setTouch(this._IHeroData, this.equipArr);
                comp.eqlv1.node.active = false;
            }
            this.initEmbattle();

        })
    }

    /**拖拽装备到合成或者强化位置上 */
    protected onBlessEquip(_, param: GParam) {
        let info = param.get<EquipPutInfo>();
        let equipData = GameMgr.RBagData.getEquipDataById(info.equipId);
        //是否可以放入合成槽
        let isBool = false;
        if (info.site != BLESS.BLESS3) {
            if (info.site != BLESS.BLESS2) {
                let bless0 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS0]);
                let bless1 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS1]);
                if ((bless0 && info.site == BLESS.BLESS1) && (bless0.quality == equipData.quality)) {
                    isBool = true;
                    this._trait = equipData.quality;
                } else if ((bless1 && info.site == BLESS.BLESS0) && (bless1.quality == equipData.quality)) {
                    isBool = true;
                    this._trait = equipData.quality;
                } else {
                    if (!bless0 && !bless1 && equipData) {
                        isBool = true;
                    }
                }
                if (isBool) {
                    this.blessView(info, equipData);
                } else {
                    GameMgr.uiMgr.showToast(JXLocales.tip.bless);
                }

            } else {
                this.blessView(info, equipData);
            }

        } else {
            for (let i = 0; i < this._readyBless.length; i++) {
                if (this._readyBless[i] == info.equipId) {
                    this._readyBless[i] = null;
                    let child = this.equipArr[i].getChildByName('JXItem');
                    if (child) {
                        child.destroy();
                        this.initEmbattle();
                    }
                }
            }
        }
    }

    /**合成强化面板信息动态改变 */
    protected initView() {
        var bless0 = null;
        var bless1 = null;
        var bless2: REquireItem = null;
        var numStr = null;
        var str = null;
        //合成框0有数据
        if (this._readyBless[BLESS.BLESS0] && this._readyBless[BLESS.BLESS0] != null) {
            bless0 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS0]);
            if (bless0) {
                this.blessLv[BLESS.BLESS0].string = 'LV:' + bless0.sLv + '';
            }
        } else {
            this.blessLv[BLESS.BLESS0].string = '';
        }
        //合成框1有数据
        if (this._readyBless[BLESS.BLESS1] && this._readyBless[BLESS.BLESS1] != null) {
            bless1 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS1]);
            if (bless1) {
                this.blessLv[BLESS.BLESS1].string = 'LV:' + bless1.sLv + ''
            }
        } else {
            this.blessLv[BLESS.BLESS1].string = '';
        }
        //强化框2有数据
        if (this._readyBless[BLESS.BLESS2] && this._readyBless[BLESS.BLESS2] != null) {
            bless2 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS2]);
            this.strView.active = true;

            if (bless2) {
                if (bless2.sLv > 0) {
                    this.strLab.string = '+' + bless2.sLv + ' ' + bless2.itemData.raw.name;
                } else {
                    this.strLab.string = '' + bless2.itemData.raw.name;
                }

                let odds = GameMgr.lvUpData.getRaw<SLvUpDataRaw>(bless2.sLv + 1).odds;
                if (odds == 1) {
                    str = '成功率：' + 100 + "%";
                } else {
                    numStr = odds < 1 ? ((odds * 100).toFixed() + "%") : odds.toString();
                    str = L(JXLocales.bless["info" + BLESS.BLESS2], numStr);
                }

                //强化表“moneyUp”字段，为消耗资源加成。
                //每次强化消耗资源等于：装备表“[100,2,10]”*强化表（1+moneyUp）。
                let coin = new RJXItem(bless2.itemData.raw.expend);
                coin.num += (1 + GameMgr.lvUpData.getRaw<SLvUpDataRaw>(bless2.sLv + 1).moneyUp);
                let strengthenBuff = GameMgr.lUserData.getUserBuff(BUFFINFO.strengthenResConsumption);
                if (strengthenBuff > 0) {
                    coin.num -= coin.num * strengthenBuff;
                }
                this.strcoinCount.string = Math.floor(coin.num) + '';

                // this.assetImpl.prefab(Res.prefab.item.jxItem, (prefab: cc.Prefab) => {
                //     if (!this._qhItem) {
                //         let comp = this.assetImpl.addGChild<JXItem>(prefab);
                //         comp.node.parent = this.strBtn;
                //         comp.node.setPosition(0, 0);
                //         this._qhItem = comp;
                //     }
                //     let bless2 = null;

                //     if (this._readyBless[BLESS.BLESS2] && this._readyBless[BLESS.BLESS2] != null) {
                //         bless2 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS2]);
                //         let coin = new RJXItem(bless2.itemData.raw.expend);
                //         coin.num += (1 + GameMgr.lvUpData.getRaw<SLvUpDataRaw>(bless2.sLv + 1).moneyUp);
                //         let strengthenBuff = GameMgr.lUserData.getUserBuff(BUFFINFO.strengthenResConsumption);
                //         if (strengthenBuff > 0) {
                //             coin.num -= coin.num * strengthenBuff;
                //         }
                //         let btn = new RJXItem([100, 3, Math.floor(coin.num)]);
                //         this._qhItem.setView(btn, ITEM_DETAIL_FLAG.MATERIAL_STYLE_LINE | ITEM_DETAIL_FLAG.NOT_TOUCH | ITEM_DETAIL_FLAG.ICON_SCALE)//| ITEM_DETAIL_FLAG.FONTHECHENG | ITEM_DETAIL_FLAG.MATERIAL_NO_HAVE
                //     }
                // })

                let videoForging: number = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.videoForging);

                let numAdStr = videoForging < 1 ? ((videoForging * 100).toFixed() + "%") : videoForging.toString();

                // let adStr = L(JXLocales.bless["info" + BLESS.BLESS2], numAdStr);
                this.strAdRate.string = str;
                this.strAdRedRate.string = '+' + numAdStr;
                this.strRate.string = str;
            }
        } else {
            this.strView.active = false;
            this.strLab.string = '';
            this.strRate.string = '';
        }
        //合成框 0 1 都要数据
        if (bless0 && bless1) {
            let equipFitMoney = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.equipFitMoney);
            let num = equipFitMoney[this._trait - 1];

            // this.assetImpl.spriteAtlasFrame(this.blessImg, Res.texture.views.icon, 'icon_100');
            // this.numLab.string = LCoin(num) + '';
            this.assetImpl.prefab(Res.prefab.item.jxItem, (prefab: cc.Prefab) => {
                if (!this._qhItem) {
                    let comp = this.assetImpl.addGChild<JXItem>(prefab);
                    comp.node.parent = this.synthesisBtn;
                    comp.node.setPosition(10, 0);
                    this._qhItem = comp;
                }
                let btn = new RJXItem([100, 3, num]);
                this._qhItem.setView(btn, ITEM_DETAIL_FLAG.MATERIAL_STYLE_LINE | ITEM_DETAIL_FLAG.MATERIAL_NO_HAVE | ITEM_DETAIL_FLAG.NOT_TOUCH | ITEM_DETAIL_FLAG.FONTHECHENG | ITEM_DETAIL_FLAG.ICON_SCALE)
            })

        } else {
            this.blessImg.spriteFrame = null;
            this.numLab.string = '';
        }
    }

    /**视频强化成功率 */
    protected adStrRate() {
        this._isUseAdRate = true;
        GameMgr.sdkMgr.watchAd(() => {
            this._isUseAdRate = false;
            this._isAddAdRate = true;
            this.strengthenClick();
        }, () => {
            GameMgr.uiMgr.showToast("广告加载失败");
            this._isAddAdRate = false;
            this._isUseAdRate = false;
            // this.strengthenClick();
        })
    }

    /**初始化View */
    protected initEmbattle() {
        this.initView();
        if (!this._listView) {
            this.assetImpl.prefab(Res.prefab.item.jxItem, (prefab: cc.Prefab) => {
                this._listView = new GListView({
                    scrollview: this.equipView,
                    mask: this.view,
                    content: this.content,
                    itemTpl: cc.instantiate(prefab),
                    itemSetter: this.onItemSetter.bind(this),
                    column: 6,
                    row: 3,
                    gapY: 20,
                    gapX: 20,
                    padingY: 0,
                    padingX: 10,
                    isCbClass: true,
                    isWidget: false,
                });
                this.dealWithData()
            })
        } else {
            this.dealWithData()
        }
    }

    /**初始每个装备框 */
    public onItemSetter(item: JXItem, data: string, index: number) {
        if (data) {
            let equipData = GameMgr.RBagData.getEquipDataById(data);
            let equip = equipData.itemData;
            let jumpEquip: jumpEquip = {
                insId: equipData.insId,
                bool: item.equipUse,
                site: 0
            }
            item.eqlv1.node.active = false;
            item.setView(equip, ITEM_DETAIL_FLAG.BLESS | ITEM_DETAIL_FLAG.ICON_SCALE, () => {
                GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.EquipDetailsCtrl, equipData, jumpEquip, this._IHeroData, DETAILSBTN.DETAILSBTN1);
            }, equipData.insId);
            item.setTouch(this._IHeroData, this.equipArr);
        } else {
            item.eqlv1.node.active = false;
            let equip = new RJXItem([0, 0, 0]);
            item.setView(equip, ITEM_DETAIL_FLAG.NULLICON);
        }

    }

    /**处理数据 */
    protected dealWithData() {
        let curMax = 18;
        let data = GameMgr.RBagData.getHeroEquip(this._IHeroData.tableId);
        let equip = data.equip;
        let book = data.book;
        equip = this.isWear(equip);
        let boolBook = this.synthesis.active;
        book = GameMgr.RBagData.getAllBook(boolBook);
        book = this.isWear(book);
        curMax -= equip.length;
        curMax -= book.length;
        if (curMax < 0) {
            curMax = 0;
        }
        let blank = new Array(curMax);
        let equipSorts = [IHeroSort.sortEquipZhanli];
        let equipSort = (a: string, b: string) => {
            let equipDataA = GameMgr.RBagData.getEquipDataById(a);
            let equipDataB = GameMgr.RBagData.getEquipDataById(b);
            return IHeroSort.sortsEquire(equipSorts, equipDataA, equipDataB);
        }
        equip.sort(equipSort);
        let arr = [...equip, ...book, ...blank];
        this._listView.setData(arr);
    }

    /**筛选是否穿戴过 */
    protected isWear(arr: string[]): string[] {
        let boolEquip = false;//是否穿戴该装备
        let brush = [];//刷新数组
        // console.log('处理数据', arr);
        for (let i = 0; i < this._readyBless.length; i++) {
            if (this._readyBless[i] && this._readyBless[i] != null) {
                brush.push(this._readyBless[i]);
            }
        }

        if (!this.strengthen.active) {
            this._IHeroData.equips.forEach((equips) => {
                arr.forEach((value) => {
                    if (value == equips) {
                        brush.push(value);//存入需要刷新的数组
                    }
                })
            })
        }


        brush.forEach((brush) => {
            arr.forEach((value, count) => {
                if (brush == value) {
                    arr.splice(count, 1);
                }
            })
        })

        // arr.forEach((value, index) => {
        //     boolEquip = false;//未穿戴该装备

        //     this._IHeroData.equips.forEach((equips) => {
        //         if (boolEquip) {
        //             return;
        //         }
        //         if (value == equips) {
        //             brush.push(value);//存入需要刷新的数组
        //             boolEquip = true;//已穿戴改装备
        //         }
        //     })

        //     //处理背包里已穿戴的装备 返回需要渲染的装备
        //     if (index == arr.length - 1) {
        //         let length = arr.length;
        //         for (let i = 0; i < length; i++) {
        //             for (let j = 0; j < brush.length; j++) {
        //                 if (brush[j] == arr[i]) {
        //                     if (!this.strengthen.active) {
        //                         arr.splice(i, 1);
        //                     }
        //                 }
        //             }
        //         }
        //         // console.log('处理数据1', arr);
        //     }
        // })
        return arr
    }

    /**点击合成按钮 */
    public synthesisClick() {
        if (this._readyBless[BLESS.BLESS0] && this._readyBless[BLESS.BLESS1] && this._readyBless[BLESS.BLESS0] != null && this._readyBless[BLESS.BLESS1] != null) {
            let bool = false;
            let equipFitMoney = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.equipFitMoney);
            let num = equipFitMoney[this._trait - 1];
            let yushi = new RJXItem([CURRENCY.YUSHI, ITEM_TYPE.CURRENCY, num]);

            /**合成buff */
            let syntheticBuff = GameMgr.lUserData.getUserBuff(BUFFINFO.syntheticConsumptionRes);
            if (syntheticBuff > 0) {
                yushi.num -= yushi.num * syntheticBuff;
            }

            let result = GameMgr.itemMgr.testCost(yushi, 1, true);
            if (result.enough) {
                bool = true;
            } else {
                GameMgr.uiMgr.showToast(result.tip)
            }

            if (bool) {
                if (this.synthesisEffectL.node.active) {
                    this.synthesisEffectL.setAnimation(0, JXEBlessAniNames.hecheng, false);

                } else {
                    this.synthesisEffectL.node.active = true;
                }
                if (this.synthesisEffectR.node.active) {
                    this.synthesisEffectR.setAnimation(0, JXEBlessAniNames.hecheng, false);

                } else {
                    this.synthesisEffectR.node.active = true;
                }
                let bless0 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS0]);
                let bless1 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS1]);
                if (!bless0 || !bless1) {
                    GameMgr.uiMgr.showToast(JXLocales.tip.result);
                    return;
                }
                let arr = [];
                let equipFitOdds = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.equipFitOdds);
                let probability = equipFitOdds[bless1.quality - 1];
                for (let i = 0; i < 100; i++) {
                    if (i <= probability * 100) {
                        arr.push(BLESS.BLESS1);
                    } else {
                        arr.push(BLESS.BLESS0);
                    }
                }

                arr = MathEx.fisherYatesShuffle(arr);
                let index = Math.floor(Math.random() * arr.length);

                //穿戴等级
                // let lv = null;

                var minLv = null;
                var maxLv = null;
                let lv0 = bless0.itemData.raw.lv;
                let lv1 = bless1.itemData.raw.lv;
                if (lv0 > lv1) {
                    // lv = MathEx.random((lv1 / 10), (lv0 / 10));

                    minLv = lv1;
                    maxLv = lv0;
                } else if (lv1 > lv0) {
                    // lv = MathEx.random((lv0 / 10), (lv1 / 10));
                    minLv = lv0;
                    maxLv = lv1;
                } else {
                    minLv = lv0;
                    maxLv = lv1;
                }
                // lv = lv * 10;

                //强化等级
                let sLv = null;
                let sLv0 = bless0.sLv;
                let sLv1 = bless1.sLv;
                if (sLv0 > sLv1) {
                    sLv = MathEx.random(sLv0, sLv1);
                } else if (sLv1 > sLv0) {
                    sLv = MathEx.random(sLv1, sLv0);
                } else if (sLv1 == sLv1) {
                    sLv = sLv0;
                }
                //品质
                let trait = bless0.quality;
                //合成晋级成功 最高品质为6
                if (arr[index] == BLESS.BLESS1) {
                    trait++;
                    if (trait >= SQUAD_BUTTON.SCHOLAR) {
                        trait = SQUAD_BUTTON.SCHOLAR;
                    }
                } else {
                    trait = bless0.quality;
                }
                //取到改职业类型
                let type = GameMgr.heroData.getRaw<SHeroDataRaw>(this._IHeroData.tableId).type;
                //如果装备类型一致则返回一致的装备类型 否则旧随机装备类型
                let seat = bless0.itemData.raw.seat == bless1.itemData.raw.seat ? bless1.itemData.raw.seat : Math.floor(Math.random() * EQUIP_PART.BINGSHU1);
                //如果装备类型一致则返回一致的装备类型 true 否则false
                let bool = bless0.itemData.raw.seat == bless1.itemData.raw.seat ? true : false;
                //取到合成后可以派发装备的奖池
                let equipList = GameMgr.equipData.getJackpot(type, this._IHeroData.tableId, minLv, maxLv, trait, seat);
                let randomNum = null;
                let arrsNum = null;
                let equip: SEquipDataRaw = null;
                if (bool) {
                    let arrs = [];
                    equipList.forEach((v: SEquipDataRaw, index) => {
                        if (v.seat == seat) {
                            arrs.push(v);
                        }
                        if (index == equipList.length - 1) {
                            arrsNum = Math.floor(Math.random() * arrs.length);
                            equip = arrs[arrsNum];
                        }
                    })
                } else {
                    // console.log('取到合成后可以派发装备的奖池', equipList);
                    randomNum = Math.floor(Math.random() * equipList.length);
                    // console.log('equipList[randomNum]', equipList[randomNum], sLv);
                    equip = equipList[randomNum];
                }


                if (equip) {
                    //获得新装备
                    // GCtrl.ES.emit(CMsg.client.bag.onBagItemChange, [[equip.id, ITEM_TYPE.EQUIPDATA, 1]]);
                    let SynthesisEquip: SynthesisEquip = {
                        /**装备id */
                        id: equip.id,
                        /**强化等级 */
                        slv: sLv,
                        /**类型 */
                        type: ITEM_TYPE.EQUIPDATA,
                        /**数量 */
                        num: 1
                    }
                    GCtrl.ES.emit(CMsg.client.equip.AddSynthesisEquip, SynthesisEquip);
                    //移除旧装备
                    GCtrl.ES.emit(CMsg.client.equip.ondelEquip, this._readyBless[BLESS.BLESS0]);
                    GCtrl.ES.emit(CMsg.client.equip.ondelEquip, this._readyBless[BLESS.BLESS1]);
                    this._readyBless = [];
                    for (let i = 0; i < this.equipArr.length; i++) {
                        let child = this.equipArr[i].getChildByName('JXItem');
                        if (child) {
                            child.destroy();
                        }
                    }
                    this.initEmbattle();
                    this.setRedPoint();
                    let raw = GameMgr.heroData.getRaw<SHeroDataRaw>(this._IHeroData.tableId)
                    // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.bless, { msg: raw.name + "合成完成" });
                    GCtrl.ES.emit(CMsg.client.bag.onBagItemChange, [[CURRENCY.YUSHI, ITEM_TYPE.CURRENCY, -num]])
                } else {
                    GameMgr.uiMgr.showToast(JXLocales.tip.result);
                }
            }
        }
    }

    /**点击强化按钮 */
    public strengthenClick() {
        // console.log('点击强化按钮');
        //强化表“levelOff”字段，强化失败是否掉级，0=不掉级，1=掉0~1级，2=掉0~2级~
        if (!this._readyBless[BLESS.BLESS2]) {
            return
        }
        let BLESS2 = GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS2]);
        //是否可以强化
        let bool = false;
        //每个装备在“装备表”会有“type”字段，判断该装备是否可强化。
        if (BLESS2.itemData.raw.type == BLESS.BLESS0) {
            //强化表“moneyUp”字段，为消耗资源加成。
            //每次强化消耗资源等于：装备表“[100,2,10]”*强化表（1+moneyUp）。
            let yushi = new RJXItem(BLESS2.itemData.raw.expend);
            yushi.num += (1 + GameMgr.lvUpData.getRaw<SLvUpDataRaw>(BLESS2.sLv + 1).moneyUp);
            let strengthenBuff = GameMgr.lUserData.getUserBuff(BUFFINFO.strengthenResConsumption);
            if (strengthenBuff > 0) {
                yushi.num -= yushi.num * strengthenBuff;
            }
            yushi.num = Math.floor(yushi.num);
            // console.log('coin', yushi);
            let result = GameMgr.itemMgr.testCost(yushi, 1, true);
            if (result.enough) {
                bool = true;
            } else {
                if (this._isAddAdRate) {
                    bool = true;
                } else {
                    GameMgr.uiMgr.showToast(result.tip)
                }
            }
            if (bool && !this._isUseAdRate) {
                if (this.strEffect.node.active) {
                    this.strEffect.setAnimation(0, JXEBlessAniNames.animation, false)
                } else {
                    this.strEffect.node.active = true;
                }

                //强化表“odds”字段，装备该强化等级的成功率。
                let odds = GameMgr.lvUpData.getRaw<SLvUpDataRaw>(BLESS2.sLv + 1).odds;
                // console.log('无视频强化成功率增益', odds);
                let oddsList = [];
                let raw = GameMgr.heroData.getRaw<SHeroDataRaw>(this._IHeroData.tableId)
                if (this._isAddAdRate) {
                    let videoForging: number = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.videoForging);
                    odds += videoForging;
                    if (odds >= 1) {
                        odds == 1;
                    }
                    // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.bless, { msg: raw.name + "进行视屏强化" });
                    // console.log('累加视频强化成功率增益', odds);
                } else {
                    // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.bless, { msg: raw.name + "进行金币强化" });
                }
                odds *= 100;
                let num = 100 - odds;
                if (num > 0) {
                    for (let i = 0; i < num; i++) {
                        oddsList.push(BLESS.BLESS0);
                    }
                }
                for (let j = 0; j < odds; j++) {
                    oddsList.push(BLESS.BLESS1);
                }
                oddsList = MathEx.fisherYatesShuffle(oddsList);
                let index = Math.floor(Math.random() * oddsList.length);
                if (oddsList[index] == BLESS.BLESS1) {
                    AudioMgr.Ins().playEffect(Res.audio.qh);
                    let info: EquipAddInfo = {
                        equipId: this._readyBless[BLESS.BLESS2],
                        exp: 1
                    }
                    AudioMgr.Ins().playEffect(Res.audio.qhSuc)
                    GCtrl.ES.emit(CMsg.client.equip.onAddEquipSlv, new GParam(info))
                    if (!this._isAddAdRate) {
                        GCtrl.ES.emit(CMsg.client.bag.onBagItemChange, [[yushi.id, yushi.type, -yushi.num]])
                    }
                    GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.strengthenView, BLESS2, BLESSEND_INFO.strSus);
                    this.setRedPoint();
                    this.initView();
                } else {
                    AudioMgr.Ins().playEffect(Res.audio.qh);
                    // 强化表“levelOff”字段，强化失败是否掉级，0=不掉级，1=掉0~1级，2=掉0~2级~
                    let levelOff = GameMgr.lvUpData.getRaw<SLvUpDataRaw>(BLESS2.sLv).levelOff;
                    let info: EquipAddInfo = {
                        equipId: this._readyBless[BLESS.BLESS2],
                        exp: -levelOff,
                    }
                    GCtrl.ES.emit(CMsg.client.equip.onAddEquipSlv, new GParam(info))
                    GameMgr.uiMgr.showToast(JXLocales.tip.blessLose);

                    GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.strengthenView, BLESS2, BLESSEND_INFO.strFail);
                    this.initView();
                }
                // console.log('强化等级的成功率', odds, GameMgr.RBagData.getEquipDataById(this._readyBless[BLESS.BLESS2]));
            }
        } else {
            GameMgr.uiMgr.showToast(JXLocales.tip.unBless);
        }
    }
}